package com.authcode.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author Mr.yuan
 * @version v1.0
 * @date 2019/8/1 14:03
 **/
@Slf4j
@ControllerAdvice
public class ControllerException {

    @ExceptionHandler(Exception.class)
    public ModelAndView forwardErrorPage(Exception e){
        log.error("error info -{},stack info -{}",e.getMessage(),e);
        ModelAndView view = new ModelAndView();
        view.addObject("code", HttpStatus.METHOD_NOT_ALLOWED);
        view.addObject("msg",e.getMessage());
        view.addObject("stackInfo",e);
        view.setViewName("error");
        return view;
    }
}
